import Vue from "vue";

export const columns = (that, dis) => {

    return [
        {
            type: 'index',
            title: '序号',
            width: 55,
            align: 'center',
        },
        {
            key: 'goodsImgUrls',
            title: '图片',
            width: 55,
            align: 'center',
            render: (h, params) => {
                return h('div', {
                    on: {
                        click: () => {
                            that.showBigImage(params)
                        }
                    }
                }, [
                    h('Avatar', {
                        props: {
                            src: 'http://127.0.0.1:8001/' + params.row.goodsImgUrls,
                            size: "large",
                            shape: "square",
                        }
                    })
                ])
            }
        },
        {
            key: 'barcode',
            title: '条形码',
            minWidth: 105,
            align: 'center',
        },
        {
            key: 'goodsName',
            title: '名称',
            minWidth: 120,
            align: 'center',
        },
        // {
        //     key: 'goodsBuyingPriceAverage',
        //     title: '近期平均进货价格',
        //     minWidth: 70,
        //     align: 'center',
        //     render: (h, params) => {
        //         return h('div', [
        //             (params.row.goodsBuyingPriceAverage / 100).toFixed(2)
        //         ])
        //     }
        // },
        {
            key: 'buying',
            title: '进货价格',
            width: 95,
            align: 'center',
            render: (h, params) => {
                return h('Input', {
                    props: {
                        value: (params.row.buying / 100).toFixed(2),
                        size: 'small',
                    },
                    on: {
                        'on-blur': (val) => {
                            that.toStockInfoData[params.index].buying = val.target.value * 100
                            Vue.set(that.toStockInfoData, params.index, that.toStockInfoData[params.index])
                        }
                    },
                })
            }
        },
        {
            key: 'goodsMfd',
            title: '生产日期',
            width: 148,
            align: 'center',
            render: (h, params) => {
                return h('date-picker', {
                    props: {
                        value: params.row.goodsMfd,
                        size: 'small',
                        placement: 'left-start'
                    },
                    on: {
                        'on-change': (val) => {
                            let exp = that.$moment(new Date(val).getTime() + that.toStockInfoData[params.index].goodsKeepDay * 24 * 60 * 60 * 1000).format("YYYY-MM-DD");
                            that.toStockInfoData[params.index].goodsMfd = val
                            that.toStockInfoData[params.index].goodsExp = exp
                        }
                    }
                })
            }
        },
        {
            key: 'goodsExp',
            title: '截止日期',
            width: 148,
            align: 'center',
            render: (h, params) => {
                return h('date-picker', {
                    props: {
                        value: params.row.goodsExp,
                        size: 'small',
                        placement: 'left-start'
                    },
                    on: {
                        'on-change': (val) => {
                            let mfd = that.$moment(new Date(val).getTime() - that.toStockInfoData[params.index].goodsKeepDay * 24 * 60 * 60 * 1000).format("YYYY-MM-DD");
                            that.toStockInfoData[params.index].goodsMfd = mfd
                            that.toStockInfoData[params.index].goodsExp = val
                        }
                    }
                })
            }
        },
        {
            key: 'count',
            title: '入库数量',
            width: 75,
            align: 'center',
            render: (h, params) => {
                return h('Input', {
                    props: {
                        value: params.row.count,
                        size: 'small',
                    },
                    on: {
                        'on-blur': (val) => {
                            that.toStockInfoData[params.index].count = val.target.value
                            Vue.set(that.toStockInfoData, params.index, that.toStockInfoData[params.index])
                        }
                    },
                })
            }
        },
        {
            key: 'action',
            title: '操作',
            align: 'center',
            fixed: 'right',
            width: '80',
            render: (h, params) => {
                return h('div', [
                    h(
                        'CustomPopTipButton',
                        {
                            props: {
                                confirmTitle: '确定删除？',
                                btnType: 'error',
                                btnSize: 'small',
                                btnText: '删除',
                                disabled: dis,
                            },
                            on: {
                                ok: () => {
                                    that.deleteToStockInfo(params.index)
                                },
                            },
                        },
                        '删除'
                    )
                ])
            }
        }
    ]
}